package tongcheng.com.tongcheng.base.main.dailishangcenter;

import android.os.Bundle;
import android.support.annotation.IdRes;
import android.support.v4.app.FragmentTransaction;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.RadioGroup;

import com.readystatesoftware.systembartint.SystemBarTintManager;

import butterknife.Bind;
import tongcheng.com.tongcheng.R;
import tongcheng.com.tongcheng.base.BaseActivity;
import tongcheng.com.tongcheng.base.main.FragmentOrder;
import tongcheng.com.tongcheng.utils.AndroidBug54971Workaround;
import tongcheng.com.tongcheng.utils.Setting;

public class DPersonCenterActivity extends BaseActivity {

    @Bind(R.id.main_rb1)
    RadioButton mMainRb1;

    public static RadioButton mMainRb2;

    public static  RadioGroup mMainRg;
    @Bind(R.id.main_fragment)
    LinearLayout mMainFragment;


    @Override
    public Integer initResid() {
        return R.layout.activity_dperson_center;
    }

    @Override
    public void initCreate(Bundle savedInstanceState) {
        mMainRb2 = (RadioButton) findViewById(R.id.main_rb2);
        mMainRg = (RadioGroup) findViewById(R.id.main_rg);
        FragmentTransaction transactions = getTransaction();
        int temp = Setting.getTemp();
        if(temp == 1){
            Setting.setTemp(2);
            mMainRb2.setChecked(true);
            transactions.replace(R.id.main_fragment, new FragmentOrder());
        }else {
            mMainRb1.setChecked(true);
            transactions.replace(R.id.main_fragment, new DFragmentPerson());
        }
        transactions.commit();
        AndroidBug54971Workaround.assistActivity(findViewById(R.id.allmain));
//        hideBottomUIMenu();


        final SystemBarTintManager tintManager = getTintManager();
        mMainRg.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup radioGroup, @IdRes int i) {
                final FragmentTransaction transaction = getTransaction();
                switch (i) {
                    case R.id.main_rb1:

                        transaction.replace(R.id.main_fragment, new DFragmentPerson());
                        if (tintManager != null) {
                            tintManager.setStatusBarTintResource(R.color.title_barno);
                        }

                        break;
                    case R.id.main_rb2:
                        transaction.replace(R.id.main_fragment, new FragmentOrder());
                        if (tintManager != null) {
                            tintManager.setStatusBarTintResource(R.color.title_bar);
                        }

                        break;
                }
                transaction.commit();
            }
        });
    }
}
